---
title: Spec - howl.ui.Editor
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.ui.editor">howl.ui.Editor</h1>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="w">
</span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">cursor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">cursor</span><span class="w">
</span><span class="n">selection</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">selection</span><span class="w">
</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Gtk</span><span class="p">.</span><span class="nc">OffscreenWindow</span><span class="o">!</span><span class="w">
</span><span class="n">window</span><span class="o">\</span><span class="n">add</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!</span><span class="w">
</span><span class="n">window</span><span class="o">\</span><span class="n">show_all</span><span class="o">!</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">app</span><span class="o">\</span><span class="n">pump_mainloop</span><span class="o">!</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'default'</span><span class="w">
  </span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
  </span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="w">
  </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w">
  </span><span class="n">selection</span><span class="o">\</span><span class="n">remove</span><span class="o">!</span></code></pre>


<h4 id=".current_line-is-a-shortcut-for-the-current-buffer-line">.current_line is a shortcut for the current buffer line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">current_line</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code></pre>


<h4 id=".current_context-returns-the-buffer-context-at-the-current-position">.current_context returns the buffer context at the current position</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nwʘrld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">context</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">current_context</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Context'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w"> </span><span class="n">context</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">context</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id=".newline()-adds-a-newline-at-the-current-position">.newline() adds a newline at the current position</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">newline</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏ\nllo'</span></code></pre>


<h4 id="insert(text)-inserts-the-text-at-the-cursor,-and-moves-cursor-after-text">insert(text) inserts the text at the cursor, and moves cursor after text</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">' world'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo world'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span></code></pre>


<h4 id="delete_line()-deletes-the-current-line">delete_line() deletes the current line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_line</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'world!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="copy_line()-copies-the-current-line">copy_line() copies the current line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\n'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">copy_line</span><span class="o">!</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\nhƏllo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="join_lines-joins-the-current-line-with-the-one-after">join_lines joins the current line with the one after</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\n    world!\n'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">join_lines</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo world!\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="forward_to_match(string)-moves-the-cursor-to-next-occurence-of-&lt;string&gt;,-if-found-in-the-line">forward_to_match(string) moves the cursor to next occurence of &lt;string&gt;, if found in the line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏll\to\n    world!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">forward_to_match</span><span class="w"> </span><span class="s1">'l'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">forward_to_match</span><span class="w"> </span><span class="s1">'l'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">forward_to_match</span><span class="w"> </span><span class="s1">'o'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">forward_to_match</span><span class="w"> </span><span class="s1">'w'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="backward_to_match(string)-moves-the-cursor-back-to-previous-occurence-of-&lt;string&gt;,-if-found-in-the-line">backward_to_match(string) moves the cursor back to previous occurence of &lt;string&gt;, if found in the line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'h\tƏllo\n    world!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">backward_to_match</span><span class="w"> </span><span class="s1">'l'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">backward_to_match</span><span class="w"> </span><span class="s1">'l'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">backward_to_match</span><span class="w"> </span><span class="s1">'h'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">backward_to_match</span><span class="w"> </span><span class="s1">'w'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

<div class="spec-group spec-group-2">

<h2 id=".active_lines">.active_lines</h2>
<div class="spec-group spec-group-3">

<h3 id="(with-no-selection-active)">(with no selection active)</h3>

<h4 id="is-a-table-containing-.current_line">is a table containing .current_line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">active_lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">current_line</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-a-selection-active)">(with a selection active)</h3>

<h4 id="is-a-table-of-lines-involved-in-the-selection">is a table of lines involved in the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">active_lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">active_lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">active_lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">active_lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">active_lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id=".active_chunk">.active_chunk</h2>

<h4 id="is-a-chunk">is a chunk</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'Chunk'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">active_chunk</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(with-no-selection-active)">(with no selection active)</h3>

<h4 id="is-a-chunk-encompassing-the-entire-buffer-text">is a chunk encompassing the entire buffer text</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">active_chunk</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-a-selection-active)">(with a selection active)</h3>

<h4 id="is-a-chunk-containing-the-current-the-selection">is a chunk containing the current the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'llo\nw'</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">active_chunk</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="indent()">indent()</h3>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-does-not-provide-a-indent-method)">(when mode does not provide a indent method)</h3>

<h4 id="does-nothing">does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-provides-a-indent-method)">(when mode provides a indent method)</h3>

<h4 id="calls-that-passing-itself-a-parameter">calls that passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">method</span><span class="p">]:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">[</span><span class="n">method</span><span class="p">]).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">),</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span><span class="w">

      </span><span class="k">if</span><span class="w"> </span><span class="n">method</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'toggle_comment'</span></code></pre>


<h4 id="uses-the-buffer-mode-when-the-one-to-use-is-ambiguous">uses the buffer mode when the one to use is ambiguous</h4>

<pre class="highlight moonscript"><code><span class="n">mode1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'//'</span><span class="w">
</span><span class="n">mode2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'#'</span><span class="w">

</span><span class="n">mode1_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode1</span><span class="w">
</span><span class="n">mode2_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode2</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode1_reg</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode2_reg</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">_buffer</span><span class="p">.</span><span class="n">styling</span><span class="o">\</span><span class="n">apply</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">
  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'s1'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'toggle_comment_test|s1'</span><span class="p">,</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'// ab\n// c'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">11</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="comment()">comment()</h3>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-does-not-provide-a-comment-method)">(when mode does not provide a comment method)</h3>

<h4 id="does-nothing">does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-provides-a-comment-method)">(when mode provides a comment method)</h3>

<h4 id="calls-that-passing-itself-a-parameter">calls that passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">method</span><span class="p">]:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">[</span><span class="n">method</span><span class="p">]).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">),</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span><span class="w">

      </span><span class="k">if</span><span class="w"> </span><span class="n">method</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'toggle_comment'</span></code></pre>


<h4 id="uses-the-buffer-mode-when-the-one-to-use-is-ambiguous">uses the buffer mode when the one to use is ambiguous</h4>

<pre class="highlight moonscript"><code><span class="n">mode1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'//'</span><span class="w">
</span><span class="n">mode2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'#'</span><span class="w">

</span><span class="n">mode1_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode1</span><span class="w">
</span><span class="n">mode2_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode2</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode1_reg</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode2_reg</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">_buffer</span><span class="p">.</span><span class="n">styling</span><span class="o">\</span><span class="n">apply</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">
  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'s1'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'toggle_comment_test|s1'</span><span class="p">,</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'// ab\n// c'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">11</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="uncomment()">uncomment()</h3>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-does-not-provide-a-uncomment-method)">(when mode does not provide a uncomment method)</h3>

<h4 id="does-nothing">does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-provides-a-uncomment-method)">(when mode provides a uncomment method)</h3>

<h4 id="calls-that-passing-itself-a-parameter">calls that passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">method</span><span class="p">]:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">[</span><span class="n">method</span><span class="p">]).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">),</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span><span class="w">

      </span><span class="k">if</span><span class="w"> </span><span class="n">method</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'toggle_comment'</span></code></pre>


<h4 id="uses-the-buffer-mode-when-the-one-to-use-is-ambiguous">uses the buffer mode when the one to use is ambiguous</h4>

<pre class="highlight moonscript"><code><span class="n">mode1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'//'</span><span class="w">
</span><span class="n">mode2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'#'</span><span class="w">

</span><span class="n">mode1_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode1</span><span class="w">
</span><span class="n">mode2_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode2</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode1_reg</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode2_reg</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">_buffer</span><span class="p">.</span><span class="n">styling</span><span class="o">\</span><span class="n">apply</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">
  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'s1'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'toggle_comment_test|s1'</span><span class="p">,</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'// ab\n// c'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">11</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="toggle_comment()">toggle_comment()</h3>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-does-not-provide-a-toggle_comment-method)">(when mode does not provide a toggle_comment method)</h3>

<h4 id="does-nothing">does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-mode-provides-a-toggle_comment-method)">(when mode provides a toggle_comment method)</h3>

<h4 id="calls-that-passing-itself-a-parameter">calls that passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">method</span><span class="p">]:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">[</span><span class="n">method</span><span class="p">]).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">),</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span><span class="w">

      </span><span class="k">if</span><span class="w"> </span><span class="n">method</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'toggle_comment'</span></code></pre>


<h4 id="uses-the-buffer-mode-when-the-one-to-use-is-ambiguous">uses the buffer mode when the one to use is ambiguous</h4>

<pre class="highlight moonscript"><code><span class="n">mode1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'//'</span><span class="w">
</span><span class="n">mode2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">comment_syntax:</span><span class="w"> </span><span class="s1">'#'</span><span class="w">

</span><span class="n">mode1_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode1</span><span class="w">
</span><span class="n">mode2_reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode2</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode1_reg</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="n">mode2_reg</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">_buffer</span><span class="p">.</span><span class="n">styling</span><span class="o">\</span><span class="n">apply</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'whitespace'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">
  </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'s1'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="s1">'toggle_comment_test|s1'</span><span class="p">,</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'// ab\n// c'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">11</span><span class="w">
</span><span class="n">editor</span><span class="p">[</span><span class="n">method</span><span class="p">]</span><span class="w"> </span><span class="n">editor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab\nc'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test1'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'toggle_comment_test2'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="with_position_restored(f)">with_position_restored(f)</h2>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  yowser!\n  yikes!'</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span></code></pre>


<h4 id="calls-&lt;f&gt;-passing-itself-a-parameter">calls &lt;f&gt; passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">with_position_restored</span><span class="w"> </span><span class="n">f</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">f</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">)</span></code></pre>


<h4 id="restores-the-cursor-position-afterwards">restores the cursor position afterwards</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="o">\</span><span class="n">with_position_restored</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span></code></pre>


<h4 id="adjusts-the-position-should-the-indentation-have-changed">adjusts the position should the indentation have changed</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="o">\</span><span class="n">with_position_restored</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="w">
  </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">with_position_restored</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(when-&lt;f&gt;-raises-an-error)">(when &lt;f&gt; raises an error)</h3>

<h4 id="propagates-the-error">propagates the error</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'ARGH!'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">with_position_restored</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nb">error</span><span class="w"> </span><span class="s1">'ARGH!'</span></code></pre>


<h4 id="still-restores-the-position">still restores the position</h4>

<pre class="highlight moonscript"><code><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">

</span><span class="nb">pcall</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">with_position_restored</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
  </span><span class="nb">error</span><span class="w"> </span><span class="s1">'ARGH!'</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="with_selection_preserved(f)">with_selection_preserved(f)</h2>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\nhello hello hello\n'</span><span class="w">
  </span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span></code></pre>


<h4 id="calls-&lt;f&gt;-passing-itself-a-parameter">calls &lt;f&gt; passing itself a parameter</h4>

<pre class="highlight moonscript"><code><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">with_selection_preserved</span><span class="w"> </span><span class="n">f</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">f</span><span class="p">).</span><span class="n">was_called_with</span><span class="p">(</span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">editor</span><span class="p">))</span></code></pre>


<h4 id="restores-the-selected-region">restores the selected region</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="o">\</span><span class="n">with_selection_preserved</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">anchor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">cursor</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(when-buffer-is-modified-outside-the-selection)">(when buffer is modified outside the selection)</h3>

<h4 id="preserves-the-selected-text">preserves the selected text</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="o">\</span><span class="n">with_selection_preserved</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buffer</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'abc'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
  </span><span class="n">buffer</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'abc'</span><span class="p">,</span><span class="w"> </span><span class="mi">14</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">13</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">anchor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">11</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">cursor</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-no-selection-present)">(when no selection present)</h3>

<h4 id="preserves-relative-position-of-cursor">preserves relative position of cursor</h4>

<pre class="highlight moonscript"><code><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">with_selection_preserved</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buffer</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'abc\n'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
  </span><span class="n">buffer</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'abc\n'</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="paste(opts-=-{})">paste(opts = {})</h2>

<h4 id="pastes-the-current-clip-of-the-clipboard-at-the-current-position">pastes the current clip of the clipboard at the current position</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="s1">' wörld'</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">eof</span><span class="o">!</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo wörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(when-opts.clip-is-specified)">(when opts.clip is specified)</h3>

<h4 id="pastes-that-clip-at-the-current-position">pastes that clip at the current position</h4>

<pre class="highlight moonscript"><code><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">
</span><span class="n">clip</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">clipboard</span><span class="p">.</span><span class="n">current</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="s1">'wörld'</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'well '</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">eof</span><span class="o">!</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">:clip</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'well hello'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-opts.where-is-set-to-&quot;after&quot;)">(when opts.where is set to &quot;after&quot;)</h3>

<h4 id="pastes-the-clip-to-the-right-of-the-current-position">pastes the clip to the right of the current position</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\n'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="s1">'yo'</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">move_to</span><span class="w"> </span><span class="ss">line:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="ss">column:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">where:</span><span class="w"> </span><span class="s1">'after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo yo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">eof</span><span class="o">!</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">where:</span><span class="w"> </span><span class="s1">'after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo yo\n yo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-the-clip-item-has-.whole_lines-set)">(when the clip item has .whole_lines set)</h3>

<h4 id="pastes-the-clip-on-a-newly-opened-line-above-the-current">pastes the clip on a newly opened line above the current</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'cruel'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\ncruel\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="pastes-the-clip-at-the-start-of-a-line-if-ends-with-a-newline-separator">pastes the clip at the start of a line if ends with a newline separator</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'cruel\n'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\ncruel\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="positions-the-cursor-at-the-start-of-the-pasted-clip">positions the cursor at the start of the pasted clip</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'paste'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'much'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(..--when-opts.where-is-set-to-&quot;after&quot;)">(..  when opts.where is set to &quot;after&quot;)</h3>

<h4 id="pastes-the-clip-on-a-newly-opened-line-below-the-current">pastes the clip on a newly opened line below the current</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'cruel'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">where:</span><span class="w"> </span><span class="s1">'after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\ncruel\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="accounts-for-trailing-newline-separators">accounts for trailing newline separators</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'cruel\n'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">where:</span><span class="w"> </span><span class="s1">'after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\ncruel\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="handles-pasting-at-the-end-of-the-buffer">handles pasting at the end of the buffer</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'at'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'last\n'</span><span class="p">,</span><span class="w"> </span><span class="ss">whole_lines:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">column</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="w"> </span><span class="ss">where:</span><span class="w"> </span><span class="s1">'after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'at\nlast\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="(when-a-selection-is-present)">(when a selection is present)</h3>

<h4 id="deletes-the-selection-before-pasting">deletes the selection before pasting</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nwonderful\nworld'</span><span class="w">
</span><span class="n">clipboard</span><span class="p">.</span><span class="n">push</span><span class="w"> </span><span class="ss">text:</span><span class="w"> </span><span class="s1">'cruel'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="nb">select</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">start_pos</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\ncruel\nworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'cruel'</span><span class="p">,</span><span class="w"> </span><span class="n">clipboard</span><span class="p">.</span><span class="n">current</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="delete_to_end_of_line(opts)">delete_to_end_of_line(opts)</h2>

<h4 id="cuts-text-from-cursor-up-to-end-of-line">cuts text from cursor up to end of line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo world!\nnext'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_to_end_of_line</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏllo\nnext'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏllo world!\nnext'</span></code></pre>


<h4 id="handles-lines-without-eols">handles lines without EOLs</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'abc'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_to_end_of_line</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_to_end_of_line</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ab'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="deletes-without-copying-if-no_copy-is-specified">deletes without copying if no_copy is specified</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo world!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_to_end_of_line</span><span class="w"> </span><span class="ss">no_copy:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏ'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">not_equal</span><span class="w"> </span><span class="s1">'hƏllo world!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(buffer-switching)">(buffer switching)</h3>

<h4 id="restores-the-position-from-buffer.properties.position-if-present">restores the position from buffer.properties.position if present</h4>

<pre class="highlight moonscript"><code><span class="n">buf1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">buf1</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'a whole different whale'</span><span class="w">
</span><span class="n">buf1</span><span class="p">.</span><span class="n">properties</span><span class="p">.</span><span class="n">position</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">buf2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">buf2</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123\n567'</span><span class="w">
</span><span class="n">buf2</span><span class="p">.</span><span class="n">properties</span><span class="p">.</span><span class="n">position</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">line:</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="ss">column:</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="remembers-the-position-for-different-buffers">remembers the position for different buffers</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\n    world!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">buffer2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">buffer2</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'a whole different whale'</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer2</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">15</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">15</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="updates-.last_shown-for-buffer-switched-out">updates .last_shown for buffer switched out</h4>

<pre class="highlight moonscript"><code><span class="n">time</span><span class="w"> </span><span class="o">=</span><span class="w">  </span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="w">
</span><span class="n">now</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">time</span><span class="o">!</span><span class="w">
</span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">now</span><span class="w">
</span><span class="nb">pcall</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">time</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">now</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">last_shown</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(previewing)">(previewing)</h3>

<h4 id="does-not-update-last_shown-for-previewed-buffer">does not update last_shown for previewed buffer</h4>

<pre class="highlight moonscript"><code><span class="n">new_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">new_buffer</span><span class="p">.</span><span class="n">last_shown</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">preview</span><span class="w"> </span><span class="n">new_buffer</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">new_buffer</span><span class="p">.</span><span class="n">last_shown</span></code></pre>


<h4 id="updates-.last_shown-for-original-buffer-switched-out">updates .last_shown for original buffer switched out</h4>

<pre class="highlight moonscript"><code><span class="n">time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="w">
</span><span class="n">now</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">time</span><span class="o">!</span><span class="w">
</span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">now</span><span class="w">
</span><span class="nb">pcall</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">editor</span><span class="o">\</span><span class="n">preview</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">sys</span><span class="p">.</span><span class="n">time</span><span class="o">=</span><span class="w"> </span><span class="n">time</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">now</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">last_shown</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(indentation,-tabs,-spaces-and-backspace)">(indentation, tabs, spaces and backspace)</h3>

<h4 id="defines-a-&quot;tab_width&quot;-config-variable,-defaulting-to-4">defines a &quot;tab_width&quot; config variable, defaulting to 4</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span></code></pre>


<h4 id="defines-a-&quot;use_tabs&quot;-config-variable,-defaulting-to-false">defines a &quot;use_tabs&quot; config variable, defaulting to false</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span></code></pre>


<h4 id="defines-a-&quot;indent&quot;-config-variable,-defaulting-to-2">defines a &quot;indent&quot; config variable, defaulting to 2</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="defines-a-&quot;tab_indents&quot;-config-variable,-defaulting-to-true">defines a &quot;tab_indents&quot; config variable, defaulting to true</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">tab_indents</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span></code></pre>


<h4 id="defines-a-&quot;backspace_unindents&quot;-config-variable,-defaulting-to-true">defines a &quot;backspace_unindents&quot; config variable, defaulting to true</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">backspace_unindents</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="smart_tab()">smart_tab()</h3>

<h4 id="inserts-a-tab-character-if-use_tabs-is-true">inserts a tab character if use_tabs is true</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'h\tƏllo'</span></code></pre>


<h4 id="inserts-spaces-to-move-to-the-next-tab-if-use_tabs-is-false">inserts spaces to move to the next tab if use_tabs is false</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="p">)</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="inserts-a-tab-to-move-to-the-next-tab-stop-if-use_tabs-is-true">inserts a tab to move to the next tab stop if use_tabs is true</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\thƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(when-in-whitespace-and-tab_indents-is-true)">(when in whitespace and tab_indents is true)</h3>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">tab_indents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="indents-the-current-line-if-in-whitespace-and-tab_indents-is-true">indents the current line if in whitespace and tab_indents is true</h4>

<pre class="highlight moonscript"><code><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="w"> </span><span class="s1">' '</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">indent</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="n">indent</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'hƏllo'</span></code></pre>


<h4 id="moves-the-cursor-to-the-beginning-of-the-text">moves the cursor to the beginning of the text</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="corrects-any-half-off-indentation">corrects any half-off indentation</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'   hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'    hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-a-selection-is-active)">(when a selection is active)</h3>

<h4 id="right-shifts-the-lines-included-in-a-selection-if-any">right-shifts the lines included in a selection if any</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nselected\nworld!'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllo\n  selected\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-in-whitespace-and-tab_indents-is-false)">(when in whitespace and tab_indents is false)</h3>

<h4 id="just-inserts-the-corresponding-tab-or-spaces">just inserts the corresponding tab or spaces</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">tab_indents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">

</span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'    hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  \t  hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id="smart_back_tab()">smart_back_tab()</h3>
<div class="spec-group spec-group-4">

<h3 id="(when-tab_indents-is-false)">(when tab_indents is false)</h3>

<h4 id="moves-the-cursor-back-to-the-previous-tab-position">moves the cursor back to the previous tab position</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">tab_indents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏ567890'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-tab_indents-is-true)">(when tab_indents is true)</h3>

<h4 id="unindents-when-in-whitespace">unindents when in whitespace</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">tab_indents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'    567890'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  567890'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'567890'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-a-selection-is-active)">(when a selection is active)</h3>

<h4 id="left-shifts-the-lines-included-in-a-selection-if-any">left-shifts the lines included in a selection if any</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo\n  selected\nworld!'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">smart_back_tab</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\nselected\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".delete_back()">.delete_back()</h3>

<h4 id="deletes-back-by-one-character">deletes back by one character</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'Əllo'</span></code></pre>


<h4 id="deletes-previous-newline-when-at-start-of-line">deletes previous newline when at start of line</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">backspace_unindents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏlloworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">config</span><span class="p">.</span><span class="n">backspace_unindents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏlloworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="unindents-if-in-whitespace-and-backspace_unindents-is-true">unindents if in whitespace and backspace_unindents is true</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">backspace_unindents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>


<h4 id="deletes-back-if-in-whitespace-and-backspace_unindents-is-false">deletes back if in whitespace and backspace_unindents is false</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">backspace_unindents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">' hƏllo'</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(with-a-selection)">(with a selection)</h3>

<h4 id="deletes-the-selection">deletes the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">' 2\n 5'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'5'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".delete_back_word()">.delete_back_word()</h3>

<h4 id="deletes-back-by-one-word">deletes back by one word</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello world'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back_word</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello '</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(with-a-selection)">(with a selection)</h3>

<h4 id="deletes-the-selection">deletes the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">' 2\n 5'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_back_word</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'5'</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".delete_forward()">.delete_forward()</h3>

<h4 id="deletes-the-character-at-cursor">deletes the character at cursor</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(when-a-selection-is-active)">(when a selection is active)</h3>

<h4 id="deletes-the-selection">deletes the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ho'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">not_equal</span><span class="w"> </span><span class="s1">'Əll'</span><span class="p">,</span><span class="w"> </span><span class="n">clipboard</span><span class="p">.</span><span class="n">current</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-at-the-end-of-a-line)">(when at the end of a line)</h3>

<h4 id="deletes-the-line-break">deletes the line break</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld'</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">move_to</span><span class="w"> </span><span class="ss">line:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="ss">column:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏlloworld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-at-the-end-of-the-buffer)">(when at the end of the buffer)</h3>

<h4 id="does-nothing">does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">cursor</span><span class="o">\</span><span class="n">eof</span><span class="o">!</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".delete_forward_word()">.delete_forward_word()</h3>

<h4 id="deletes-forward-by-one-word">deletes forward by one word</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello world'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward_word</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'world'</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(when-a-selection-is-active)">(when a selection is active)</h3>

<h4 id="deletes-the-selection">deletes the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo'</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">delete_forward_word</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ho'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">not_equal</span><span class="w"> </span><span class="s1">'Əll'</span><span class="p">,</span><span class="w"> </span><span class="n">clipboard</span><span class="p">.</span><span class="n">current</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".shift_right()">.shift_right()</h3>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="right-shifts-the-current-line-when-nothing-is-selected,-remembering-column">right-shifts the current line when nothing is selected, remembering column</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nworld!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_right</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllo\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(with-a-selection)">(with a selection)</h3>

<h4 id="right-shifts-the-lines-included-in-the-selection">right-shifts the lines included in the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllo\nselected\nworld!'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_right</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllo\n  selected\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="adjusts-and-keeps-the-selection">adjusts and keeps the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  xx\nyy zz'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="c1">-- 'xx\nyy'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_right</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'xx\n  yy'</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">selection</span><span class="o">\</span><span class="n">range</span><span class="o">!</span><span class="w"> </span><span class="p">}</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".shift_left()">.shift_left()</h3>

<h4 id="left-shifts-the-current-line-when-nothing-is-selected,-remembering-column">left-shifts the current line when nothing is selected, remembering column</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'    hƏllo\nworld!'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_left</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllo\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(with-a-selection)">(with a selection)</h3>

<h4 id="left-shifts-the-lines-included-in-the-selection">left-shifts the lines included in the selection</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  hƏllo\n  selected\nworld!'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_left</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllo\nselected\nworld!'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="adjusts-and-keeps-the-selection">adjusts and keeps the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'    xx\n  yy zz'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="w"> </span><span class="c1">-- '  xx\nyy'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">shift_left</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  xx\nyy'</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">selection</span><span class="o">\</span><span class="n">range</span><span class="o">!</span><span class="w"> </span><span class="p">}</span></code></pre>

</div>
</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="cycle_case()">cycle_case()</h2>
<div class="spec-group spec-group-3">

<h3 id="(with-a-selection-active)">(with a selection active)</h3>

<h4 id="changes-all-lowercase-selection-to-all-uppercase">changes all lowercase selection to all uppercase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello selectëd #world'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">22</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello SELECTËD #WORLD'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="changes-all-uppercase-selection-to-titlecase">changes all uppercase selection to titlecase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello SELECTËD #WORLD HELLO'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">28</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello Selectëd #world Hello'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="changes-mixed-case-selection-to-all-lowercase">changes mixed case selection to all lowercase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello SelectËD #WorLd'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">22</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello selectëd #world'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="preserves-selection">preserves selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'select'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">anchor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">cursor</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-no-selection-active)">(with no selection active)</h3>

<h4 id="changes-all-lowercase-word-to-all-uppercase">changes all lowercase word to all uppercase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello wörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello WÖRLD'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="changes-all-uppercase-word-to-titlecase">changes all uppercase word to titlecase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello WÖRLD'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello Wörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="changes-mixed-case-word-to-all-lowercase">changes mixed case word to all lowercase</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello WörLd'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cycle_case</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello wörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="duplicate_current">duplicate_current</h2>
<div class="spec-group spec-group-3">

<h3 id="(with-an-active-selection)">(with an active selection)</h3>

<h4 id="duplicates-the-selection">duplicates the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="c1">-- 'ell'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">duplicate_current</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hellello\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="keeps-the-cursor-and-current-selection">keeps the cursor and current selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456'</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">duplicate_current</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">cursor</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">selection</span><span class="p">.</span><span class="n">anchor</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-no-active-selection)">(with no active selection)</h3>

<h4 id="duplicates-the-current-line">duplicates the current line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">duplicate_current</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello\nhello\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="cut">cut</h2>
<div class="spec-group spec-group-3">

<h3 id="(with-an-active-selection)">(with an active selection)</h3>

<h4 id="cuts-the-selection">cuts the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="c1">-- 'ell'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cut</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'ho\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ellho\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-no-active-selection)">(with no active selection)</h3>

<h4 id="cuts-the-current-line">cuts the current line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cut</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'wörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="cuts-the-empty-line">cuts the empty line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">cut</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'wörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="copy">copy</h2>
<div class="spec-group spec-group-3">

<h3 id="(with-an-active-selection)">(with an active selection)</h3>

<h4 id="copies-the-selection">copies the selection</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">selection</span><span class="o">\</span><span class="n">set</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="c1">-- 'ell'</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">copy</span><span class="o">!</span><span class="w">

</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'ellhello\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-no-active-selection)">(with no active selection)</h3>

<h4 id="copies-the-current-line">copies the current line</h4>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello\nwörld'</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">copy</span><span class="o">!</span><span class="w">

</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">editor</span><span class="o">\</span><span class="n">paste</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'hello\nhello\nwörld'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h3 id="(resource-management)">(resource management)</h3>

<h4 id="editors-are-collected-as-they-should">editors are collected as they should</h4>

<pre class="highlight moonscript"><code><span class="n">e</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">editors</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="n">e</span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">
</span><span class="n">e</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!\</span><span class="n">destroy</span><span class="o">!</span><span class="w">
</span><span class="n">e</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">collect_memory</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">editors</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">nil</span></code></pre>


<h4 id="releases-resources-after-buffer-switching">releases resources after buffer switching</h4>

<pre class="highlight moonscript"><code><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">e</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="n">b1</span><span class="w">
</span><span class="n">buffers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="n">b2</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">
</span><span class="n">editors</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">
</span><span class="n">e</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b2</span><span class="w">
</span><span class="n">e</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b1</span><span class="w">
</span><span class="n">e</span><span class="o">\</span><span class="n">to_gobject</span><span class="o">!\</span><span class="n">destroy</span><span class="o">!</span><span class="w">
</span><span class="n">e</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">editors</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">buffers</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">buffers</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(get_matching_brace)">(get_matching_brace)</h3>

<h4 id="finds-position-of-matching-opending/closing-brace">finds position of matching opending/closing brace</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">auto_pairs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="s1">'['</span><span class="p">:</span><span class="w"> </span><span class="s1">']'</span><span class="p">}</span><span class="w">

</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[]'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">3</span><span class="w">

</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[Ü]'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">2</span><span class="w">

</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1ÜÜ4[6ÜÜ9]---'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">11</span></code></pre>


<h4 id="returns-nil-for-unmatched/mismatched-braces">returns nil for unmatched/mismatched braces</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">auto_pairs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="s1">'['</span><span class="p">:</span><span class="w"> </span><span class="s1">']'</span><span class="p">}</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">']['</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">2</span><span class="w">

</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'([]]'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="o">\</span><span class="n">get_matching_brace</span><span class="w"> </span><span class="mi">4</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(config-updates)">(config updates)</h3>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">editor2</span><span class="w">
</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">editor2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span></code></pre>


<h4 id="buffer-config-updates-affect-containing-editor-only">buffer config updates affect containing editor only</h4>

<pre class="highlight moonscript"><code><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">line_numbers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">editor2</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">line_numbers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">true</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">line_numbers</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">true</span><span class="w"> </span><span class="n">editor2</span><span class="p">.</span><span class="n">line_numbers</span><span class="w">

</span><span class="n">editor2</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">line_numbers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">true</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">line_numbers</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">false</span><span class="w"> </span><span class="n">editor2</span><span class="p">.</span><span class="n">line_numbers</span></code></pre>


<h4 id="buffer-mode-change-triggers-config-refresh-for-containing-editor">buffer mode change triggers config refresh for containing editor</h4>

<pre class="highlight moonscript"><code><span class="n">mode1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">mode2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test_mode1'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode1</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test_mode2'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode2</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">configure</span><span class="w"> </span><span class="s1">'test_mode1'</span><span class="p">,</span><span class="w">
  </span><span class="ss">line_numbers:</span><span class="w"> </span><span class="kc">false</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">configure</span><span class="w"> </span><span class="s1">'test_mode2'</span><span class="p">,</span><span class="w">
  </span><span class="ss">line_numbers:</span><span class="w"> </span><span class="kc">true</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'test_mode1'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">false</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">line_numbers</span><span class="w">

</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'test_mode2'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">true</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">line_numbers</span><span class="w">

</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'test_mode1'</span><span class="w">
</span><span class="n">howl</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'test_mode2'</span></code></pre>

</div>
</div>
